home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume13 / labels < prev    next >
Encoding:
Internet Message Format  |  1988-01-31  |  43.5 KB

  1. Subject:  v13i046:  Program to make mailing labels
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Joe Chen <joec%wasat.usc.edu@OBERON.USC.EDU>
  7. Posting-number: Volume 13, Issue 46
  8. Archive-name: labels
  9.  
  10.  
  11. LABELS is a label formatting program.  It formats labels/mailing lists
  12. according to user-defined label forms.  This program has been fully
  13. tested under Sun Unix 3.2 (BSD UNIX) and should work on any BSD UNIX
  14. systems.  It should also work under other UNIX systems with little
  15. changes.  As for non-Unix systems, like MS-DOS, you would need lex
  16. and yacc for the PC, or obtain lex.yy.c and y.tab.* from an UNIX system.
  17.  
  18.                         Joe S. Chen
  19.  
  20. ---------------------------------------------------------------------------
  21. Phones at work: (213) 743-5363, (213) 743-5935; at home: (818) 571-5304
  22. University Computing Services, University of Southern California
  23. UUCP: {sdcrdcf, uscvax}!oberon!wasat!joec
  24. ARPA: joec@wasat.usc.edu, joec@ecla.usc.edu
  25. ---------------------------------------------------------------------------
  26.  
  27. ----------CUT HERE----------CUT HERE----------CUT HERE----------CUT HERE------
  28. #!/bin/sh
  29. # This is a shell archive, meaning:
  30. # 1. Remove everything above the #!/bin/sh line.
  31. # 2. Save the resulting text in a file.
  32. # 3. Execute the file with /bin/sh (not csh) to create the files:
  33. #    INSTALL
  34. #    Makefile
  35. #    main.c
  36. #    labels.l
  37. #    labels.y
  38. #    labels.man
  39. #    1083.lbl
  40. #    1083f.lbl
  41. #    1083t.lbl
  42. #    6080.lbl
  43. #    6080f.lbl
  44. #    6080t.lbl
  45. #    6083.lbl
  46. #    6083f.lbl
  47. #    6083t.lbl
  48. export PATH; PATH=/bin:$PATH
  49. echo shar: extracting "'INSTALL'" '(891 characters)'
  50. if test -f 'INSTALL'
  51. then
  52.     echo shar: over-writing existing file "'INSTALL'"
  53. fi
  54. cat << \SHAR_EOF > 'INSTALL'
  55. Installation Procedure:
  56.  
  57. After extracting files from the shell archive, modify the following
  58. variables in Makefile:
  59.  
  60.     DESTDIR        Destination directory, where the program
  61.             will be installed.
  62.  
  63.     FRMDIR        Directory (doesn't have to exist) where
  64.             pre-defined forms will reside.
  65.  
  66.     LNAME        Name of the program.
  67.  
  68.     CFLAGS        Define System where this program will
  69.             run under.
  70.  
  71.  
  72. If you want to set a default form, you must edit the beginning
  73. section of main.c.
  74.  
  75. To compile LABELS, type:
  76.  
  77. %make
  78.  
  79. and press carriage return.  To install LABELS, type
  80.  
  81. %make install
  82.  
  83. and press carriage return, and the program and preset forms
  84. will be installed in the proper directories.  To install
  85. the man page, you can simply copy the file 'labels.1' to
  86. your man directory (e.g. /usr/man/man1).
  87.  
  88.  
  89. To re-package labels, type
  90.  
  91. %make shar
  92.  
  93. and press return.  The archived file 'labels.shar' will be the
  94. new shell archive.
  95. SHAR_EOF
  96. echo shar: extracting "'Makefile'" '(2809 characters)'
  97. if test -f 'Makefile'
  98. then
  99.     echo shar: over-writing existing file "'Makefile'"
  100. fi
  101. cat << \SHAR_EOF > 'Makefile'
  102. #                -- MAKEFILE (UNIX) --
  103. #
  104. # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  105. # @@                                                                         @@
  106. # @@                    Mailing List Label Formatter                         @@
  107. # @@                  Program Maintenance Specification                      @@
  108. # @@                    (C) Copyright 1987 by Joe Chen                       @@
  109. # @@                         All Rights Reserved                             @@
  110. # @@                                                                         @@
  111. # @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  112. #
  113. # Program created by Joe Chen - Jul 24, 1987
  114. #
  115. # *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  116.  
  117. # Directory where LABELS is to be installed (please specify the full path)
  118. DESTDIR = /usr/pollux/jchen/bin
  119.  
  120. # Directory where label forms can be found (please specify the full path)
  121. FRMDIR = /usr/pollux/jchen/bin/lib
  122.  
  123. # Program name
  124. LNAME = labels
  125.  
  126. # Compiling flags UNIX, BSD (USG and MSDOS are valid, but not fully supported)
  127. # NOTE: This program has been fully tested on Sun UNIX only.
  128. CFLAGS = -DBSD -DUNIX
  129.  
  130. CC = cc -c -g $(CFLAGS)
  131. YACC = yacc
  132. LEX = lex
  133. LINK = cc
  134.  
  135. # *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  136.  
  137. OBJS = y.tab.o lex.yy.o main.o
  138.  
  139.  
  140. labels: $(OBJS)
  141.     @echo char \*rev_date = \"`date`\"\; > revdate.c
  142.     @echo Linking $(LNAME)...
  143.     @${LINK} $(OBJS) revdate.c -o $(LNAME)
  144.     @rm -f revdate.c revdate.o
  145.     @echo 
  146.     @echo \`$(LNAME)\' Compiled.
  147.  
  148. y.tab.c: labels.y
  149.     @echo Running Yacc...
  150.     @${YACC} -d labels.y
  151.  
  152. y.tab.o: y.tab.c
  153.     @echo Compiling: y.tab.c
  154.     @${CC} y.tab.c
  155.  
  156. lex.yy.c: labels.l
  157.     @echo Running Lex...
  158.     @${LEX} labels.l
  159.  
  160. lex.yy.o: lex.yy.c y.tab.h
  161.     @echo Compiling: lex.yy.c
  162.     @${CC} lex.yy.c
  163.  
  164. main.o: main.c Makefile
  165.     @echo Compiling: main.c
  166.     @${CC} -DFDIR=\"$(FRMDIR)\" main.c
  167.  
  168. install:
  169.     @echo Installing \`$(LNAME)\' in $(DESTDIR)...
  170.     @rm -f $(DESTDIR/$(LNAME)
  171.     @cp $(LNAME) $(DESTDIR)/$(LNAME)
  172.     @strip $(DESTDIR)/$(LNAME)
  173.     @chmod 755 $(DESTDIR)/$(LNAME)
  174.     @echo
  175.     @echo Placing Form Definitions in $(FRMDIR)...
  176.     @echo mkdir $(FRMDIR) 2\> /dev/null \; exit 0 > mklib
  177.     @chmod u+x mklib
  178.     @./mklib
  179.     @rm -f mklib
  180.     @chmod 755 $(FRMDIR)
  181.     @cp *.lbl $(FRMDIR)
  182.     @chmod 644 $(FRMDIR)/*.lbl
  183.     @make man
  184.     @echo 
  185.     @echo \`$(LNAME)\' installed.
  186.  
  187. clean:
  188.     @echo Cleaning Directory...
  189.     @rm -f *.o *\~ y.tab.* lex.yy.c $(LNAME)
  190.     @echo 
  191.     @echo Done!
  192.  
  193. man:
  194.     @echo
  195.     @echo Processing a raw man page: $(LNAME).1
  196.     @/lib/cpp -P -DLIBDIR=$(FRMDIR) -DLNAME=$(LNAME) -DPROGDIR=$(DESTDIR) \
  197.         $(LNAME).man > $(LNAME).1
  198.  
  199.  
  200. shar:
  201.     @echo Shell Archiving \($(LNAME)\.shar\)...
  202.     @shar INSTALL Makefile main.c labels.l labels.y labels.man \
  203.         *.lbl > $(LNAME).shar
  204.     @echo 
  205.     @echo Done!
  206. SHAR_EOF
  207. echo shar: extracting "'main.c'" '(17102 characters)'
  208. if test -f 'main.c'
  209. then
  210.     echo shar: over-writing existing file "'main.c'"
  211. fi
  212. cat << \SHAR_EOF > 'main.c'
  213. /*                     -- MAIN.C --
  214.  
  215. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  216. @@                                                                           @@
  217. @@                       Mailing List Label Formatter                        @@
  218. @@                                Main Module                                @@
  219. @@                      (C) Copyright 1987 by Joe Chen                       @@
  220. @@                           All Rights Reserved                             @@
  221. @@                                                                           @@
  222. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  223.  
  224. You may freely distribute this software to others.  But there are
  225. few rules you must follow:
  226.  
  227. 1. You don't profit from it.  You may however ask for minimal fees to
  228.    cover shipping and handling.
  229.  
  230. 2. This program is copyrighted, meaning you may not modify or enhance
  231.    this software and market it.  You may make changes to suit your
  232.    local needs.  Any enhancements are welcomed.
  233.  
  234. 3. Please honor the author by not removing or replacing his name from
  235.    the source codes.
  236.  
  237.  
  238. Feel free to contact me if you have any questions.
  239.  
  240.                     Joe Chen
  241.  
  242. ---------------------------------------------------------------------------
  243. Phones at work: (213) 743-5363, (213) 743-5935; at home: (818) 571-5304
  244. University Computing Services, University of Southern California
  245. UUCP: {sdcrdcf, uscvax}!oberon!wasat!joec
  246. ARPA: joec@wasat.usc.edu, joec@ecla.usc.edu
  247. ---------------------------------------------------------------------------
  248.  
  249. Program created by Joe Chen - Jul 24, 1987
  250.  
  251. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  252.  
  253. */
  254.  
  255. /* Internal default form: 32x11x3 */
  256.  
  257. #define DEF_FORM "1083"        /* form name here at USC        */
  258.  
  259. #define ISTRING    NULL        /* initial escape sequence    */
  260. #define IFILL    12        /* fill n rows for adjustments    */
  261. #define FOFFS     0        /* form offset (from top)    */
  262. #define POFFS     0        /* page offset (from left)    */
  263.  
  264. #define LWIDTH    32        /* width (in chars) of each label */
  265. #define LHGAP     4        /* horizontal gap (in chars) between labels */
  266. #define LVGAP     1        /* vertical gap (# of lines) between labels */
  267. #define LCROSS     3        /* number of labels accross */
  268. #define LMLINES    11        /* Maximum lines per label  */
  269. #define LOFFSET     4        /* offset (in chars) from left edge */
  270.                 /* of each label */
  271. #define LROWS     0        /* labels per page, 0=don't care*/
  272.  
  273.  
  274. /*****************************************************************************/
  275. #include <stdio.h>
  276.  
  277. #define QUIT        (perror(argv[0]),dsp_usg(argv[0]),exit(-1))
  278. #define FEXT        ".lbl"    /* file extension for form definition file  */
  279. #define GETC(x)        (((ch=getc(x))=='\n')?line_num++,ch:ch);
  280.  
  281. #ifdef BSD
  282. #include <sys/types.h>
  283. #include <sys/dir.h>
  284. #endif BSD
  285.  
  286. char *def_form = DEF_FORM;    /* default label form                */
  287.  
  288. char *def_istring = ISTRING;    /* initial string/escape sequence           */
  289.  
  290. char *l_istring;
  291.  
  292. int l_ifill = IFILL;        /* Initial label fill for manual adjustments*/
  293.  
  294. int l_foffs = FOFFS;        /* form offset (from top)            */
  295. int l_poffs = POFFS;        /* page offset (from left)            */
  296. int l_width = LWIDTH;        /* width of one label (in characters)       */
  297. int l_hgap  = LHGAP;        /* horizontal gap between labels (in chars) */
  298. int l_vgap  = LVGAP;        /* vertical gap between labels (in chars)   */
  299. int l_cross = LCROSS;        /* number of labels across one row          */
  300. int l_mlines= LMLINES;        /* maximum printable lines per label        */
  301. int l_offset= LOFFSET;        /* offset printing of data (in chars)       */
  302. int l_lrows = LROWS;        /* rows of labels per page                  */
  303.  
  304. FILE *infile = stdin, *outfile = stdout;
  305. int line_num = 1;
  306.  
  307. #define T    1
  308. #define F    0
  309.  
  310. extern char *malloc(), *getcwd();
  311. extern char *rev_date;            /* supplied by Makefile            */
  312. extern FILE *yyin;            /* from lex                */
  313.  
  314. char *inpf = NULL, *outf = NULL;    /* pointer to file names            */
  315. char *form = NULL;            /* pointer to form name             */
  316.  
  317. char **fmt_arry;            /* line formatter            */
  318.  
  319. char *version = "1.1";
  320.  
  321. #ifdef UNIX
  322. #ifdef BSD
  323. static char *os_title = "BSD UNIX Version";
  324. #else
  325. #ifdef USG
  326. static char *os_title = "AT&T UNIX Version";
  327. #endif USG
  328. #endif BSD
  329. #endif UNIX
  330.  
  331. #ifdef MSDOS
  332. static char *os_title = "MS-DOS Verson";
  333. #endif MSDOS
  334.  
  335. /****************************************************************************
  336.   dsp_usg() [Private function] - Display a brief usage info
  337.  
  338.   parameters:    name            Name of this program
  339.  
  340.   exit flags:    none
  341. ****************************************************************************/
  342.  
  343. static void dsp_usg(name)
  344.      char *name;
  345. {
  346.   printf("\nUsage: %s [-f <label form>] [<input file> [output file]]\n",
  347.      name);
  348.   printf("   or: %s -h\n", name);
  349. #ifdef BSD
  350.   printf("   or: %s -l\n", name);    /* list predefined forms */
  351. #endif BSD
  352.   printf("\nWhere: <label form>  is defined in %s,\n",FDIR);
  353.   printf("                     or defined by user in the current directory.");
  354.   printf("\n       <input file>  is a text file containing raw labels.\n");
  355.   printf("       <output file> is the formatted label output.\n");
  356.   printf("       -h            displays this help.\n");
  357.   printf("       -l            lists all predefined forms.\n\n");
  358. } /* dsp_usg() */
  359.  
  360. /****************************************************************************
  361.   list_forms() [Private function] - List predefined forms (BSD Unix only)
  362.  
  363.   parameters:    name        program name (for error display purpose)
  364.  
  365.   exit flags:    none
  366. ****************************************************************************/
  367.  
  368. static void list_forms(name)
  369.      char *name;
  370. {
  371. #ifdef UNIX
  372. #ifdef BSD
  373.   DIR *dirp;            /* directory pointer */
  374.   struct direct *dp;        /* pointer to a directory record */
  375.   char *ext_ptr;        /* extension pointer */
  376.   char tmp[MAXNAMLEN+1], ch, *cur_dir;
  377.   int header = F;
  378.   FILE *f;
  379.  
  380.   if ((dirp = opendir(FDIR)) == (DIR *)NULL) {
  381.     fprintf(stderr,"%s: Cannot Open Directory: %s\n",name, FDIR);
  382.     return;
  383.   }
  384.  
  385.   if ((cur_dir = getcwd(NULL, 100)) == (char *)NULL) {
  386.     fprintf(stderr,"FATAL ERROR: Insufficient Memory\n");
  387.     exit(-1);
  388.   }
  389.   chdir(FDIR);        /* change to directory containing the form defs */
  390.  
  391.   for (dp = readdir(dirp); dp != (struct direct *)NULL; dp = readdir(dirp)) {
  392.     if (strlen(dp->d_name) <= strlen(FEXT))
  393.       continue;
  394.     ext_ptr = &dp->d_name[strlen(dp->d_name)-strlen(FEXT)];
  395.     if (!strcmp(ext_ptr, FEXT)) {    /* must have the same extension */
  396.       (void) strcpy(tmp, dp->d_name);
  397.       /* ignore extension */
  398.       tmp[strlen(tmp)-strlen(FEXT)] = '\0';
  399.       if (!header) {
  400.     fprintf(stderr,"Preset Forms\tRemarks\n");
  401.     fprintf(stderr,"------------\t-------\n");
  402.     header = T;
  403.       }
  404.       /* print out the name of the form */
  405.       fprintf(stderr,"%s\t\t", tmp);
  406.  
  407.       if ((f=fopen(dp->d_name,"r")) == (FILE *)NULL)
  408.     fprintf(stderr,"(Form Unreadable)\n");
  409.       else {
  410.     /* Display the first line, if it is a remark */
  411.     if (getc(f) != '#')
  412.       fprintf(stderr,"(No Remark)\n");
  413.     else {
  414.       while ((ch=getc(f)) == ' ');        /* skip leading spaces */
  415.       ungetc(ch, f);
  416.       while ((ch=getc(f)) != '\n') {
  417.         putc(ch, stderr);            /* print comment       */
  418.         if (feof(f))
  419.           break;
  420.       } /* keep reading info */
  421.       fprintf(stderr,"\n");
  422.     } /* display a line of info */
  423.     fclose(f);
  424.       } /* query file */
  425.     }
  426.   } /* for all entries */
  427.   chdir(cur_dir);        /* change back the directory */
  428.   free(cur_dir);
  429. #endif BSD
  430.  
  431. #ifdef USG
  432.   /* System V listing: for now, just use ls */
  433.   char cmd[100];
  434.   (void) sprintf(cmd, "/bin/ls %s/*%s", FDIR, FEXT);
  435.   (void) system(cmd);
  436. #endif USG
  437. #endif UNIX
  438.  
  439. #ifdef MSDOS
  440.   fprintf(stderr,"Not implemented at this time for MSDOS\n");
  441. #endif MSDOS
  442. } /* list_forms() */
  443.  
  444. /****************************************************************************
  445.   get_record() [Private function] - Reads one label info into internal buffer
  446.  
  447.   parameters:    rec        Buffer for holding one label record
  448.  
  449.   exit flags:    0        end-of-file or no label between periods
  450.         >0        number of lines read for this label
  451. ****************************************************************************/
  452.  
  453. static int get_record(rec)
  454.      char **rec;
  455. {
  456.   char ch, *p;
  457.   int i = 0, j;
  458.  
  459.   do {
  460.     p = rec[i];        /* next line */
  461.     /* read in one line */
  462.     for (j = 0, p[j] = '\0'; ; j++) {
  463.       if (!feof(infile)) {
  464.     if (j > (l_width-l_offset)) {        /* line too long */
  465.       fprintf(stderr,"Line %d: Line too long (%d) - Truncated\n",
  466.           line_num, l_width);
  467.       p[l_width-l_offset] = '\0';        /* force termination */
  468.       while (getc(infile) != '\n')
  469.         if (feof(infile))
  470.           return i;
  471.       line_num++;
  472.       break;
  473.     } /* line too long */
  474.  
  475.     if ((p[j]=getc(infile)) == '\n') {    /* read in next char */
  476.       line_num++;
  477.       p[j] = '\0';
  478.       break;
  479.     } /* if end-of-line, go read next line */
  480.  
  481.     if ((!j)&&(p[j]=='.')) {        /* end of label */
  482.       while (getc(infile) != '\n')
  483.         if (feof(infile))
  484.           break;                /* end of file */
  485.       line_num++;
  486.       return i;                /* return lines read */
  487.     } /* end of label detected */
  488.       }
  489.       else
  490.     return i;
  491.     } /* for */
  492.   } while (++i < l_mlines);    
  493.  
  494.   if ((ch=getc(infile)) != '.')
  495.     fprintf(stderr,"Line %d: Lines Exceeded Limit (%d) - Ignoring the Rest\n",
  496.         line_num,l_mlines);
  497.   ungetc(ch, infile);
  498.  
  499.   /* truncating... */
  500.   while (1) {
  501.     if (getc(infile) == '.') {    /* at the end already */
  502.       while(getc(infile) != '\n')
  503.     if (feof(infile))
  504.       break;
  505.       line_num++;
  506.       return i;
  507.     } /* skip to next label */
  508.     while(getc(infile) != '\n')
  509.       if (feof(infile))
  510.     return i;
  511.     line_num++;
  512.   }
  513. } /* get_record() */
  514.  
  515. /****************************************************************************
  516.   main() [Public function] - Startup routine
  517.  
  518.   parameters:    argc        Number of command-line arguments
  519.         argv        argument array
  520.  
  521.   exit flags:    0        Program terminate normally
  522.         <>0        Error (of some sort) occurred, program aborted
  523. ****************************************************************************/
  524.  
  525. main(argc, argv)
  526.      int argc;
  527.      char **argv;
  528. {
  529.   char **row, **rec, *p, *tmpbuf;
  530.   int arg_limit = 3;    /* argument handler (too hard to explain) */
  531.   register i, j, k, l;
  532.   int cur_col, lines, started = F, row_count;
  533.   FILE *ffile;            /* to read form file */
  534.  
  535.   l_istring = def_istring;
  536.  
  537.   if (argc > 1) {
  538.     /* get brief usage */
  539.     if ((!strcmp(argv[1], "help"))||(!strcmp(argv[1], "-h"))) {
  540.       dsp_usg(argv[0]);
  541.       exit(0);
  542.     }
  543.  
  544.     /* list defined forms in FDIR */
  545.     if (!strcmp(argv[1], "-l")) {
  546.       list_forms(argv[0]);
  547.       exit(0);
  548.     }
  549.   } /* check for single argument */
  550.  
  551.   fprintf(stderr,
  552.       "LABELS: Label/Mailing List Formatter - %s\n", os_title);
  553.   fprintf(stderr,"Release %s - Compiled %s\n\n", version, rev_date);
  554.  
  555.   form = def_form;
  556.  
  557.  
  558.   /* allocate space to hold data format for each line */
  559.   if ((fmt_arry = (char **) malloc(l_mlines*sizeof(char *))) ==(char **)NULL)
  560.     QUIT;
  561.   for (i=l_mlines; i ; i--) {
  562.     fmt_arry[i-1] = malloc(l_width+1);
  563.     if (fmt_arry[i-1] == (char *)NULL)
  564.       QUIT;
  565.     (void) strcpy(fmt_arry[i-1], "%s");    /* default format, data only */
  566.   }
  567.  
  568.   if (argc < 2)
  569.     goto ckarg;
  570.  
  571.   /* Check if user specified his/her own form */
  572.   if (!strcmp(argv[1], "-f")) {
  573.     char *frm_name;
  574.  
  575.     if (argc == 2) {
  576.       fprintf(stderr,"%s: Form name is missing!\n",argv[0]);
  577.       exit(-1);
  578.     }
  579.  
  580.     /* Make a complete file name for form */;
  581.     frm_name = malloc(strlen(FDIR)+strlen(argv[2]+strlen(FEXT)+2));
  582.     if (frm_name == (char *)NULL)
  583.       QUIT;
  584.     arg_limit += 2;
  585.  
  586.     form = argv[2];
  587.  
  588.     /* create a path to open the label form file */
  589.     (void) strcpy(frm_name, FDIR);
  590. #ifdef MSDOS
  591.     (void) strcat(frm_name, "\\");
  592. #else
  593.     (void) strcat(frm_name, "/");
  594. #endif MSDOS
  595.     (void) strcat(frm_name, form);
  596.     (void) strcat(frm_name, FEXT);    /* form extension */
  597.  
  598.     /* open file */
  599.     if ((ffile=fopen(frm_name, "r")) == (FILE *)NULL) {
  600.       /* trouble opening file from library directory, try current directory */
  601.       (void) strcpy(frm_name, ".");
  602. #ifdef MSDOS
  603.       (void) strcat(frm_name, "\\");
  604. #else
  605.       (void) strcat(frm_name, "/");
  606. #endif MSDOS
  607.       (void) strcat(frm_name, form);
  608.       (void) strcat(frm_name, FEXT);    /* form extension */
  609.       if ((ffile=fopen(frm_name, "r")) == (FILE *)NULL) {
  610.     /* cannot open file in current directory either, give up */
  611.     fprintf(stderr,"%s: Cannot read form: %s\n",*argv,form);
  612.     exit(-1);
  613.       }
  614.     } /* open form */
  615.  
  616.     yyin = ffile;
  617.  
  618.     /* now parse the file */
  619.     if (yyparse()) {
  620.       fprintf(stderr,"%s: Error reading form: %s\n",*argv,form);
  621.       exit(-1);
  622.     }
  623.     free(frm_name);
  624.   } /* reading form definitions */
  625.  
  626.  ckarg:
  627.   /* Check if there are too many arguments */
  628.   if (argc > arg_limit) {
  629.     fprintf(stderr,"%s: Too many arguments\n", argv[0]);
  630.     exit(-1);
  631.   }
  632.  
  633.   /* Check if output file is given (has to be the last argument) */
  634.   if (argc > arg_limit-1) {
  635.     if ((outfile = fopen(argv[arg_limit-1], "w")) == (FILE *)NULL)
  636.       QUIT;
  637.     outf = argv[arg_limit-1];
  638.   }
  639.  
  640.   /* Check if input file is given (second to the last argument) */
  641.   if (argc > arg_limit-2) {
  642.     if ((infile = fopen(argv[arg_limit-2],"r")) == (FILE *)NULL)
  643.       QUIT;
  644.     inpf = argv[arg_limit-2];
  645.   }
  646.  
  647.   /* allocate space to hold a row of labels of n across */
  648.   if ((row = (char **) malloc(l_mlines*sizeof(char *))) == (char **)NULL)
  649.     QUIT;
  650.   for (i=l_mlines; i ; i--) {
  651.     row[i-1] = malloc(l_width*l_cross+l_hgap*(l_cross-1)+100);
  652.     if (row[i-1] == (char *)NULL)
  653.       /* insufficient memory */
  654.       QUIT;
  655.   } /* for */
  656.  
  657.   fprintf(stderr,"[Input: %s, Output: %s, Form: %s]\n",
  658.      (inpf!=(char *)NULL)?inpf:"(stdin)",
  659.      (outf!=(char *)NULL)?outf:"(stdout)", form);
  660.  
  661.   /* allocate space to hold one label of n lines */
  662.   if ((rec = (char **) malloc((l_mlines+1)*sizeof(char *))) == (char **)NULL)
  663.     QUIT;
  664.   for (i=l_mlines+1; i ; i--)        /* buffer space should be big */
  665.     if ((rec[i-1] = malloc(l_width*2)) == (char *)NULL)
  666.       QUIT;
  667.  
  668.   /* for formatting purpose */
  669.   if ((tmpbuf = malloc(l_width*2)) == (char *)NULL)
  670.     QUIT;
  671.  
  672.   row_count = l_lrows + 1;        /* ensure checking for form offset */
  673.  
  674.   /* main loop */
  675.   while(T) {
  676.     /* clear one row of labels*/
  677.     for (i = 0; i <  l_mlines; i++)
  678.       for (j = 0, k = (l_width*l_cross+l_hgap*(l_cross-1)); j < k ; j++)
  679.     row[i][j] = ' ';
  680.  
  681.     for (cur_col=0; cur_col < l_cross; cur_col++) {
  682.  
  683.       while (!(lines=get_record(rec)))    /* get one label from input         */
  684.     if (feof(infile)) {        /* if no lines read, probably eof   */
  685.       if (cur_col)
  686.         goto f;            /* flush output                     */
  687.       goto d;            /* quit                             */
  688.     }
  689.  
  690.       /* Check each input line with format string */
  691.       for (i = 0; i < lines; i++) {
  692.     if (!strcmp(fmt_arry[i], "%s"))
  693.       continue;            /* no need to format, use default   */
  694.  
  695.     (void) strcpy(tmpbuf,rec[i]);
  696.     (void) sprintf(rec[i],fmt_arry[i],tmpbuf);
  697.  
  698.     /* truncate if string too long after formatting */
  699.     if (strlen(rec[i]) > (l_width-l_offset)) {
  700.       rec[i][(l_width-l_offset)] = '\0';
  701.       fprintf(stderr,
  702.           "Line %d: Line too long after formatting (%d) - Truncated\n",
  703.           line_num-lines-1+i, l_width);
  704.     } /* string too long after formatting */
  705.       }
  706.  
  707.       for (i = j = (l_mlines-lines)/2, k = 0; i < (j+lines); i++, k++) {
  708.     p = (char *) ((int)row[i] + cur_col*(l_width+l_hgap) + l_offset);
  709.     for (l = 0; rec[k][l]; l++)
  710.       p[l] = rec[k][l];
  711.       } /* fill n lines for one label */
  712.  
  713.     } /* for one row */
  714.  
  715.   f:
  716.     if (!started) {
  717.       /* Output initial string or escape sequence to printer */
  718.       started = T;
  719.       if (l_istring != (char *)NULL)
  720.     fprintf(outfile, l_istring);
  721.       if (l_ifill) {
  722.     int kk;
  723.     /* fills n rows for manual adjustment purposes */
  724.     for (i = 0; i < l_ifill; row_count++, i++) {
  725.  
  726.       if ((row_count < l_lrows)||(!l_lrows))
  727.         kk = 0;
  728.       else {
  729.         kk = l_foffs;
  730.         row_count = 0;
  731.       }
  732.  
  733.       for (; kk < l_mlines; putc('\n', outfile), kk++) {
  734.         for (j = 0; j < l_cross; j++) {
  735.           for (k = l_poffs; k < l_width; k++)
  736.         putc('#', outfile);        /* fill one line of a label */
  737.           if (j < l_cross-1)
  738.         for (k = 0; k < l_hgap; k++)
  739.           fprintf(outfile," ");        /* make horizontal gaps     */
  740.         } /* for one line in label */
  741.       } /* for one row of label */
  742.       for (k = 0; k < l_vgap; putc('\n', outfile), k++);
  743.     } /* for n rows */
  744.       } /* if need to adjust */
  745.     } /* if initial output */
  746.  
  747.     /* print row to output file */
  748.     if ((row_count < l_lrows)||(!l_lrows))
  749.       i = 0;                /* print entire label */
  750.     else {
  751.       /* if there's a form offset, the first row of labels maybe truncated */
  752.       i = l_foffs;
  753.       row_count = 0;
  754.     }
  755.  
  756.     for (k = (l_width*l_cross+l_hgap*(l_cross-1)); i < l_mlines; i++) {
  757.       /* set an absolute length for output */
  758.       row[i][k] = '\0';
  759.  
  760.       /* if there's a page offset, we better look out */
  761.       fprintf(outfile,"%s\n", &row[i][l_poffs]);
  762.     }
  763.  
  764.     /* fill vertical gap */
  765.     for (i = 0; i < l_vgap; i++)
  766.       putc('\n', outfile);
  767.     row_count++;
  768.   } /* process entire file - while() */
  769.  
  770.  d:
  771.   if (infile != stdin)
  772.     fclose(infile);
  773.   if (outfile != stdout)
  774.     fclose(outfile);
  775.  
  776.   fprintf(stderr,"\n%s: Formatting Complete\n",argv[0]);
  777. } /* main() */
  778. SHAR_EOF
  779. echo shar: extracting "'labels.l'" '(3284 characters)'
  780. if test -f 'labels.l'
  781. then
  782.     echo shar: over-writing existing file "'labels.l'"
  783. fi
  784. cat << \SHAR_EOF > 'labels.l'
  785. %{
  786. /*                   -- LABELS.L --
  787.  
  788. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  789. @@                                                                           @@
  790. @@                       Mailing List Label Formatter                        @@
  791. @@                    Lexical Analyzer for Form Parsing                      @@
  792. @@                      (C) Copyright 1987 by Joe Chen                       @@
  793. @@                           All Rights Reserved                             @@
  794. @@                                                                           @@
  795. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  796.  
  797. You may freely distribute this software to others.  But there are
  798. few rules you must follow:
  799.  
  800. 1. You don't profit from it.  You may however ask for minimal fees to
  801.    cover shipping and handling.
  802.  
  803. 2. This program is copyrighted, meaning you may not modify or enhance
  804.    this software and market it.  You may make changes to suit your
  805.    local needs.  Any enhancements are welcomed.
  806.  
  807. 3. Please honor the author by not removing or replacing his name from
  808.    the source codes.
  809.  
  810.  
  811. Feel free to contact me if you have any questions.
  812.  
  813.                     Joe Chen
  814.  
  815. ---------------------------------------------------------------------------
  816. Phones at work: (213) 743-5363, (213) 743-5935; at home: (818) 571-5304
  817. University Computing Services, University of Southern California
  818. UUCP: {sdcrdcf, uscvax}!oberon!wasat!joec
  819. ARPA: joec@wasat.usc.edu, joec@ecla.usc.edu
  820. ---------------------------------------------------------------------------
  821.  
  822. Program created by Joe Chen - Jul 24, 1987
  823.  
  824. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  825.  
  826. */
  827.  
  828. #include <stdio.h>
  829.  
  830. #ifdef UNIX
  831. #include "y.tab.h"
  832. #else
  833. #include "ytab.h"
  834. #endif
  835.  
  836. int value, line_no = 1;
  837. extern char *form;
  838. %}
  839.  
  840. cr        \n
  841. tab        \t
  842. space        " "
  843. white_space    ({space}|{tab})
  844. spcs        {white_space}*
  845.  
  846. digit        [0-9]
  847. number        {digit}+
  848.  
  849. letter        [A-Za-z_]
  850. word        {letter}({letter}|{digit})*
  851.  
  852. %%
  853.  
  854. {spcs}            ;
  855.  
  856. #.*            ;
  857.  
  858. {cr}            {    line_no++;        }
  859.  
  860. initial            {    return(_INITIAL);    }
  861.  
  862. string            {    return(_KSTRING);    }
  863.  
  864. fill            {    return(_FILL);        }
  865.  
  866. form            {    return(_FORM);        }
  867.  
  868. page            {    return(_PAGE);        }
  869.  
  870. width            {    return(_WIDTH);        }
  871.  
  872. hgap            {    return(_HGAP);        }
  873.  
  874. vgap            {    return(_VGAP);        }
  875.  
  876. columns            {    return(_COLUMNS);    }
  877.  
  878. column            {    return(_COLUMNS);    }
  879.  
  880. format            {    return(_FORMAT);    }
  881.  
  882. offset            {    return(_OFFSET);    }
  883.  
  884. of            {    return(_OF);        }
  885.  
  886. for            {    return(_OF);        }
  887.  
  888. lines            {    return(_LINES);        }
  889.  
  890. line            {    return(_LINE);        }
  891.  
  892. rows            {    return(_ROWS);        }
  893.  
  894. is            {    return(_IS);        }
  895.  
  896. ","            {    return(_DELIM);        }
  897.  
  898. ";"            {    return(_DELIM);        }
  899.  
  900. "="            {    return(_ASSIGN);    }
  901.  
  902. ":"            {    return(_ASSIGN);    }
  903.  
  904.  
  905. {number}        {
  906.                 value = atoi(yytext);
  907.                 return(_VALUE);
  908.             }
  909.  
  910. {word}            {    return(_WORD);        }
  911.  
  912.  
  913. \"[^\"]*\"        {    return(_STRING);    }
  914.  
  915. .            {
  916.               fprintf(stderr,
  917.                 "Line %d in %s: Illegal Character: '%s'\n",
  918.                   line_no, yytext);
  919.             }
  920.  
  921. %%
  922.  
  923. /****************************************************************************
  924.   yywrap() [Public function] - lex's function when EOF is detected from yyin
  925.  
  926.   parameters:    none
  927.  
  928.   exit flags:    1        Done matching tokens from input file
  929. ****************************************************************************/
  930.  
  931. yywrap()
  932. {
  933.   return 1;
  934. } /* yywrap() */
  935. SHAR_EOF
  936. echo shar: extracting "'labels.y'" '(5508 characters)'
  937. if test -f 'labels.y'
  938. then
  939.     echo shar: over-writing existing file "'labels.y'"
  940. fi
  941. cat << \SHAR_EOF > 'labels.y'
  942. %{
  943. /*                   -- LABELS.Y --
  944.  
  945. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  946. @@                                                                           @@
  947. @@                       Mailing List Label Formatter                        @@
  948. @@                     Syntax Analyzer for Form Parsing                      @@
  949. @@                      (C) Copyright 1987 by Joe Chen                       @@
  950. @@                           All Rights Reserved                             @@
  951. @@                                                                           @@
  952. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  953.  
  954. You may freely distribute this software to others.  But there are
  955. few rules you must follow:
  956.  
  957. 1. You don't profit from it.  You may however ask for minimal fees to
  958.    cover shipping and handling.
  959.  
  960. 2. This program is copyrighted, meaning you may not modify or enhance
  961.    this software and market it.  You may make changes to suit your
  962.    local needs.  Any enhancements are welcomed.
  963.  
  964. 3. Please honor the author by not removing or replacing his name from
  965.    the source codes.
  966.  
  967.  
  968. Feel free to contact me if you have any questions.
  969.  
  970.                     Joe Chen
  971.  
  972. ---------------------------------------------------------------------------
  973. Phones at work: (213) 743-5363, (213) 743-5935; at home: (818) 571-5304
  974. University Computing Services, University of Southern California
  975. UUCP: {sdcrdcf, uscvax}!oberon!wasat!joec
  976. ARPA: joec@wasat.usc.edu, joec@ecla.usc.edu
  977. ---------------------------------------------------------------------------
  978.  
  979. Program created by Joe Chen - Jul 24, 1987
  980.  
  981. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  982.  
  983. */
  984. #include <stdio.h>
  985.  
  986. extern char *malloc(), *realloc();
  987.  
  988. extern int value, line_no;
  989. extern char yytext[], **fmt_arry, *l_istring;
  990. extern int l_width, l_hgap, l_vgap, l_columns, l_mlines, l_offset, l_cross;
  991. extern int l_ifill, l_foffs, l_poffs, l_lrows;
  992. extern FILE *form;
  993. %}
  994.  
  995. %union {
  996.   int vars;
  997. };
  998.  
  999. %token _INITIAL
  1000. %token _KSTRING
  1001. %token _FORM
  1002. %token _PAGE
  1003. %token _FILL
  1004. %token _WIDTH
  1005. %token _HGAP
  1006. %token _VGAP
  1007. %token _COLUMNS
  1008. %token _LINES
  1009. %token _ROWS
  1010. %token _OFFSET
  1011. %token _FORMAT
  1012. %token _OF
  1013. %token _LINE
  1014. %token _IS
  1015. %token _ASSIGN
  1016. %token _DELIM
  1017. %token _VALUE
  1018. %token _STRING
  1019. %token _WORD
  1020.  
  1021. %type <vars> variable
  1022.  
  1023. %%
  1024.  
  1025. cmd        : stmts
  1026.         ;
  1027.  
  1028. stmts        : stmts delim stmt
  1029.         | stmt
  1030.         ;
  1031.  
  1032. delim        : _DELIM delim
  1033.         |
  1034.         ;
  1035.  
  1036. stmt        : param_stmt_val
  1037.         | fmt_stmt
  1038.         | init_stmt
  1039.         ;
  1040.  
  1041. param_stmt_val    : variable is _VALUE
  1042.         {
  1043.           switch($1) {
  1044.           case _WIDTH:
  1045.             l_width = value;
  1046.             break;
  1047.           case _HGAP:
  1048.             l_hgap = value;
  1049.             break;
  1050.           case _VGAP:
  1051.             l_vgap = value;
  1052.             break;
  1053.           case _COLUMNS:
  1054.             l_cross = value;
  1055.             break;
  1056.           case _LINES: {
  1057.             if (l_mlines < value) {
  1058.               int i;        /* need to adjust format buffer */
  1059.               fmt_arry=(char **)realloc(fmt_arry,value*sizeof(char *));
  1060.               if (fmt_arry == (char **)NULL)
  1061.             goto e;
  1062.               /* add new format lines */
  1063.               for (i=l_mlines; i < value; i++) {
  1064.             fmt_arry[i] = malloc(l_width+1);
  1065.             if (fmt_arry[i] == (char *)NULL)
  1066.               goto e;
  1067.             (void) strcpy(fmt_arry[i], "%s");
  1068.               }
  1069.             } /* adjust the format buffer */
  1070.             l_mlines = value;
  1071.             break;
  1072.           e:
  1073.             fprintf(stderr,"Fatal Error: Insufficient Memory\n");
  1074.             exit(-1);
  1075.           }
  1076.           case _OFFSET:
  1077.             /* label column offset */
  1078.             l_offset = value;
  1079.             break;
  1080.           case _FORM:
  1081.             /* form offset value */
  1082.             l_foffs = value;
  1083.             break;
  1084.           case _PAGE:
  1085.             /* page offset value */
  1086.             l_poffs = value;
  1087.             break;
  1088.           case _ROWS:
  1089.             /* rows per label */
  1090.             l_lrows = value;
  1091.             break;
  1092.           } /* set various variables */
  1093.         }
  1094.         ;
  1095.  
  1096. variable    : _WIDTH
  1097.         {
  1098.           $$=_WIDTH;
  1099.         }
  1100.         | _HGAP
  1101.         {
  1102.           $$=_HGAP;
  1103.         }
  1104.         | _VGAP
  1105.         {
  1106.           $$=_VGAP;
  1107.         }
  1108.         | _COLUMNS
  1109.         {
  1110.           $$=_COLUMNS;
  1111.         }
  1112.         | _LINES
  1113.         {
  1114.           $$=_LINES;
  1115.         }
  1116.         | _LINE
  1117.         {
  1118.           $$=_LINES;
  1119.         }
  1120.         | _ROWS
  1121.         {
  1122.           $$=_ROWS;
  1123.         }
  1124.         | _OFFSET
  1125.         {
  1126.           $$=_OFFSET;
  1127.         }
  1128.         | _FORM _OFFSET
  1129.         {
  1130.           $$=_FORM;
  1131.         }
  1132.         | _PAGE _OFFSET
  1133.         {
  1134.           $$=_PAGE;
  1135.         }
  1136.         | _WORD
  1137.         {
  1138.           $$=0;
  1139.           fprintf(stderr,"Line %d in %s: Unknown variable: %s\n",
  1140.               line_no, form, yytext);
  1141.         }
  1142.         ;
  1143.  
  1144. fmt_stmt    : _FORMAT _OF line _VALUE is _STRING
  1145.         {
  1146.           if (value > l_mlines) {
  1147.             fprintf(stderr,"Line %d in %s: Line Number Execeeded ",
  1148.                 line_no, form);
  1149.             fprintf(stderr,"Maximum (%d); Format Ignored\n",l_mlines);
  1150.           }
  1151.           else {
  1152.             /* supercede format */
  1153.             (void) strcpy(fmt_arry[value-1], &yytext[1]);
  1154.             /* remove quotes */
  1155.             fmt_arry[value-1][strlen(fmt_arry[value-1])-1] = '\0';
  1156.           }
  1157.         }
  1158.         ;
  1159.  
  1160. init_stmt    : _INITIAL _KSTRING is _STRING
  1161.         {
  1162.           if ((l_istring = malloc(strlen(yytext))) == (char *)NULL) {
  1163.             fprintf(stderr,"Fatal Error: Insufficient Memory\n");
  1164.             exit(-1);
  1165.           }
  1166.           /* remove the quotations */
  1167.           (void) strcpy(l_istring, &yytext[1]);
  1168.           l_istring[strlen(l_istring)-1] = '\0';
  1169.         }
  1170.         | _INITIAL _FILL is _VALUE
  1171.         {
  1172.           /* initial fill value */
  1173.           l_ifill = value;
  1174.         }
  1175.         ;
  1176.  
  1177. line        : _LINE
  1178.         |
  1179.         ;
  1180.  
  1181. is        : _IS
  1182.         | _ASSIGN
  1183.         |
  1184.         ;
  1185.  
  1186. %%
  1187.  
  1188. /****************************************************************************
  1189.   yyerror() [Public function] - Yacc error trap function
  1190.  
  1191.   parameters:    s        Error message from yacc's LR driver
  1192.  
  1193.   exit flags:    none
  1194. ****************************************************************************/
  1195.  
  1196. yyerror(s)
  1197.      char *s;
  1198. {
  1199.   if (strcmp(s, "syntax error"))
  1200.     fprintf(stderr,"Line %d in %s: %s\n",line_no,form,s);
  1201. } /* yyerror() */
  1202.  
  1203. SHAR_EOF
  1204. echo shar: extracting "'labels.man'" '(7344 characters)'
  1205. if test -f 'labels.man'
  1206. then
  1207.     echo shar: over-writing existing file "'labels.man'"
  1208. fi
  1209. cat << \SHAR_EOF > 'labels.man'
  1210. .pl 60
  1211. .\" Man Page for LABELS
  1212. .TH LABELS 1 "2 Aug 1987"
  1213. .SH NAME
  1214. labels \- produce formatted output for label printing
  1215. .SH SYNOPSIS
  1216. .B LNAME
  1217. [
  1218. .B \-f <form>
  1219. [
  1220. .B <input file>
  1221. [
  1222. .B <output file>
  1223. ] ]
  1224. .br
  1225. .B LNAME
  1226. .B \-h
  1227. .br
  1228. .B LNAME
  1229. .B \-l
  1230. .SH DESCRIPTION
  1231. .B LNAME accepts a raw
  1232. .B <input file>
  1233. and produces a formatted
  1234. .B <output file>.
  1235. If
  1236. .B <output file>
  1237. is not specified, then formatted output will
  1238. go to standard output
  1239. .I (stdout).
  1240. If
  1241. .B <input file>
  1242. is not specified in addition to the omission of
  1243. .B <output file>,
  1244. then input will be taken from the standard input
  1245. .I (stdin).
  1246. .sp
  1247. .\" describe the format of the input file
  1248. The format of an input file is simple and straight forward.  The
  1249. following is an example:
  1250. .nf
  1251. .sp
  1252.         John Doe
  1253.         123 Main St.
  1254.         City of DownUnder, AU 9999
  1255.         .
  1256.         Susan Smith
  1257.         Label Products, Inc.
  1258.         1000 Broadway Blvd.
  1259.         Space City, DD 00001
  1260.         .
  1261. .sp
  1262. .fi
  1263. A period "." must be placed at the beginning of a new line
  1264. after completing data input for each label.
  1265. .\" describe the format of label forms
  1266. .sp
  1267. By default,
  1268. .B LNAME
  1269. prepares the output for USC-UCC standard label form (1083), which is 32 characters
  1270. wide and 11 lines long per label, and 3 labels across. The optional
  1271. .B \-f <form>
  1272. can be used to overcome the default label format.  A directory
  1273. of preset label formats can be listed by specifying the
  1274. .B \-l
  1275. parameter alone.  If a desired form is not available, the user
  1276. can define one, like the following:
  1277. .sp
  1278. .nf
  1279.         # Standard label size (32 char x 6 lines, 3 columns)
  1280.  
  1281.         width = 32, lines = 6, columns = 3
  1282.  
  1283.         # other alignments
  1284.         hgap = 4, vgap = 1, offset = 4
  1285. .fi
  1286. .sp
  1287. A line that starts with # is treated as a comment.  Various
  1288. parameters can be set by specifying the variable name, like
  1289. .I width,
  1290. and assign it to the a value, like 32.  The above form file
  1291. defines the following:
  1292. .sp
  1293. .nf
  1294.         \- Each label has maximum width of 32 characters (width=32).
  1295.         \- Each label has maximum lines of 6 (lines=6).
  1296.         \- Format for 3 labels across (columns=3).
  1297.         \- Set horizontal gap between labels to be 4 characters (hgap=4).
  1298.         \- Set vertical gap between labels to be 1 line (vgap=1).
  1299.         \- Set data offset to be 4 characters from the left (offset=4).
  1300. .fi
  1301. .sp
  1302. You may also use the
  1303. .B :
  1304. or a space in the place of
  1305. .B =.
  1306. In other words, you can use any one of the variations:
  1307. .sp
  1308. .nf
  1309.         width:32        width 32        or width = 32.
  1310. .fi
  1311. .sp
  1312. Also, you may use a semicolon in place of a comma.
  1313. .sp
  1314. There is a naming convention for such file.  Each form definition
  1315. file
  1316. .B must
  1317. have the extension
  1318. .B .lbl
  1319. and must be in the current directory in order for it to be
  1320. recognized by
  1321. .B LNAME.
  1322. For example, the above definition may be placed in
  1323. a file called
  1324. .I myform.lbl.
  1325. To format labels from an input file
  1326. .I labels.in
  1327. and save the formatted output to
  1328. .I labels.out
  1329. using
  1330. .I myform.lbl,
  1331. type:
  1332. .sp
  1333. .nf
  1334.         LNAME -f myform labels.in labels.out
  1335. .fi
  1336. .sp
  1337. .B LNAME
  1338. will search for
  1339. .I myform
  1340. from a set of preset forms.  If such form does not exist, it
  1341. will then search in user's current directory.
  1342. .sp
  1343. Many people prefer to print mailing list labels with a "To:"
  1344. attached to the first line, and the rest of the lines must
  1345. align properly.  The user may create the following form:
  1346. .sp
  1347. .nf
  1348.         # Standard label size (32 char x 6 lines, 3 columns) with "To:"
  1349.  
  1350.         lines:6; width:32
  1351.         columns:2
  1352.  
  1353.         # other alignments
  1354.         hgap:4; vgap:1; offset:0
  1355.  
  1356.         # format definition for each of the 6 lines in a label
  1357.         format for line 1 is " To: %s"
  1358.         format for line 2 is "     %s"
  1359.         format for line 3 is "     %s"
  1360.         format for line 4 is "     %s"
  1361.         format for line 5 is "     %s"
  1362.         format for line 6 is "     %s"
  1363. .fi
  1364. .sp
  1365. If the sample input data file on page 1 is used, along with the above
  1366. form, this is the result:
  1367. .nf
  1368. .sp
  1369. -----------------------------------------------------------------------
  1370. |                                |   |                                |
  1371. | To: John Doe                   |   | To: Susan Smith                |
  1372. |     123 Main St.               |   |     Label Products, Inc.       |
  1373. |     City of DownUnder, AU 9999 |   |     1000 Broadway Blvd.        |
  1374. |                                |   |     Space City, DD 00001       |
  1375. |                                |   |                                |
  1376. -----------------------------------------------------------------------
  1377. .fi
  1378. .sp
  1379. The string
  1380. .I %s
  1381. is substituted with the input data.  Thus by default, each line has
  1382. the format of "%s".
  1383. If "To:" is desired to be added to the first line, like to above example,
  1384. then the format for the first line can be defined as "To: %s".
  1385. .sp
  1386. Customized printing of labels can also be done.  Initial string of
  1387. escape sequences can be sent via the
  1388. .I "initial string"
  1389. command:
  1390. .sp
  1391. .nf
  1392.         initial string = "^[B"
  1393. .fi
  1394. .sp
  1395. where
  1396. .I "^[B"
  1397. could be an escape sequence to enable bold printing on a particular
  1398. printer.
  1399. .sp
  1400. Another useful parameter is
  1401. .I "initial fill."
  1402. Before printing labels on a line printer, the operator often needs
  1403. to re-adjust the printer.  By printing the dimensions of the label
  1404. forms, the printer can be adjusted properly before printing the
  1405. first valid label.  To fill ten rows of labels initially, the
  1406. following parameter is specified in the form definition:
  1407. .sp
  1408. .nf
  1409.         initial fill = 10
  1410. .fi
  1411. .sp
  1412. Finally, if you need a quick reminder about the program parameters,
  1413. a brief command usage can be reviewed by specifying the
  1414. .I \-h
  1415. parameter alone.
  1416. .SH LIMITATIONS
  1417. LNAME assumes that the printer to be used is using a font with
  1418. constant widths for all characters.
  1419. .SH FILES
  1420. PROGDIR/LNAME
  1421. .sp
  1422. All .lbl files in LIBDIR are predefined label form definitions.
  1423. A listing can be obtained by specifying the
  1424. .B \-l
  1425. parameter.
  1426. .SH DIAGNOSIS
  1427. Below is a list of common error messages and their descriptions.
  1428. .sp
  1429. .B "Line xxxx: Line too long (x) - Truncated"
  1430. .sp
  1431. Length of the input data at line xxxx is longer than the maximum
  1432. defined width of x.  The rest of the input on that line is truncated.
  1433. .sp
  1434. .B "Line xxxx: Line too long after formatting (x) - Truncated"
  1435. .sp
  1436. The length of the formatted string at line xxxx is longer than the
  1437. maximum width permitted, which is x.
  1438. .sp
  1439. .B "Line xxxx: Lines Exceeded Limit (x) - Ignoring the Rest"
  1440. .sp
  1441. Number of lines per label is greater than the maximum of x lines.
  1442. .sp
  1443. .B LNAME
  1444. .B ": Cannot read form:"
  1445. .I form
  1446. .sp
  1447. The form you specified with
  1448. .B \-f
  1449. is not found.  The file name must have the extension .lbl.
  1450. .sp
  1451. .B LNAME
  1452. .B ": Error reading form:"
  1453. .I form
  1454. .sp
  1455. User defined form has improper syntax, which resulted in parsing
  1456. errors.  Various parsing errors are also displayed.
  1457. .sp
  1458. .B LNAME
  1459. .B ": Too many arguments"
  1460. .sp
  1461. Too many arguments specified.  A brief program usage is displayed.
  1462. .sp
  1463. .B LNAME
  1464. .B ": Cannot Open Directory:"
  1465. .I dir
  1466. .sp
  1467. Cannot list preset forms because the directory containing form files
  1468. does not exist.
  1469. .sp
  1470. .SH BUGS
  1471. None discovered so far. Please report any bugs you may find
  1472. to the author by electronic mail.
  1473. .SH AUTHOR
  1474. .nf
  1475. Joe S. Chen, Consultant, UNIX, VMS, and TOPS-20
  1476. Phones: (213) 743-5363, (213) 743-5935
  1477. University Computing Services, University of Southern California
  1478. UUCP: {sdcrdcf, uscvax}!oberon!wasat!joec
  1479. ARPA: joec@wasat.usc.edu, joec@ecla.usc.edu
  1480. .fi
  1481. SHAR_EOF
  1482. echo shar: extracting "'1083.lbl'" '(259 characters)'
  1483. if test -f '1083.lbl'
  1484. then
  1485.     echo shar: over-writing existing file "'1083.lbl'"
  1486. fi
  1487. cat << \SHAR_EOF > '1083.lbl'
  1488. # Form 1083 (32 chars x 11 lines, 3 cols) for line printing
  1489. # Last changed: 8/3/87 by Joe. Chen, USC-UCC
  1490.  
  1491. initial fill = 12        # our operators need a lot of time to adjust!
  1492.  
  1493. width = 32, lines = 11, columns = 3
  1494.  
  1495. # other alignments
  1496. hgap = 4; vgap = 1, offset = 4
  1497. SHAR_EOF
  1498. echo shar: extracting "'1083f.lbl'" '(548 characters)'
  1499. if test -f '1083f.lbl'
  1500. then
  1501.     echo shar: over-writing existing file "'1083f.lbl'"
  1502. fi
  1503. cat << \SHAR_EOF > '1083f.lbl'
  1504. # Same as Form 1083 with "From:"
  1505. # Last changed: 8/3/87 by Joe. Chen, USC-UCC
  1506.  
  1507. initial fill = 12
  1508.  
  1509. width = 32, lines = 11, columns = 3
  1510.  
  1511. # other alignments
  1512. hgap = 4, vgap = 1, offset = 0
  1513.  
  1514. # Reformat each line
  1515. format of line  1 : "From: %s"
  1516. format of line  2 : "      %s"
  1517. format of line  3 : "      %s"
  1518. format of line  4 : "      %s"
  1519. format of line  5 : "      %s"
  1520. format of line  6 : "      %s"
  1521. format of line  7 : "      %s"
  1522. format of line  8 : "      %s"
  1523. format of line  9 : "      %s"
  1524. format of line 10 : "      %s"
  1525. format of line 11 : "      %s"
  1526. SHAR_EOF
  1527. echo shar: extracting "'1083t.lbl'" '(524 characters)'
  1528. if test -f '1083t.lbl'
  1529. then
  1530.     echo shar: over-writing existing file "'1083t.lbl'"
  1531. fi
  1532. cat << \SHAR_EOF > '1083t.lbl'
  1533. # Same as Form 1083 with "To:"
  1534. # Last changed: 8/3/87 by Joe. Chen, USC-UCC
  1535.  
  1536. initial fill : 12
  1537.  
  1538. width : 32, lines : 11, columns : 3
  1539.  
  1540. # other alignments
  1541. hgap : 4, vgap : 1, offset : 1
  1542.  
  1543. # Reformat each line
  1544. format of line  1 : "To: %s"
  1545. format of line  2 : "    %s"
  1546. format of line  3 : "    %s"
  1547. format of line  4 : "    %s"
  1548. format of line  5 : "    %s"
  1549. format of line  6 : "    %s"
  1550. format of line  7 : "    %s"
  1551. format of line  8 : "    %s"
  1552. format of line  9 : "    %s"
  1553. format of line 10 : "    %s"
  1554. format of line 11 : "    %s"
  1555. SHAR_EOF
  1556. echo shar: extracting "'6080.lbl'" '(209 characters)'
  1557. if test -f '6080.lbl'
  1558. then
  1559.     echo shar: over-writing existing file "'6080.lbl'"
  1560. fi
  1561. cat << \SHAR_EOF > '6080.lbl'
  1562. # Xerox 6080 (34 chars x 6 lines, 3 cols) for laser printing
  1563. # Last changed: 8/2/87 by Joe. Chen, USC-UCC
  1564.  
  1565. initial fill = 0
  1566.  
  1567. width = 34, lines = 6, columns = 3
  1568.  
  1569. # other alignments
  1570. hgap 0; vgap : 0, offset = 2
  1571. SHAR_EOF
  1572. echo shar: extracting "'6080f.lbl'" '(391 characters)'
  1573. if test -f '6080f.lbl'
  1574. then
  1575.     echo shar: over-writing existing file "'6080f.lbl'"
  1576. fi
  1577. cat << \SHAR_EOF > '6080f.lbl'
  1578. # Same as Form 6080 with "From:"
  1579. # Last changed: 8/2/87 by Joe. Chen, USC-UCC
  1580.  
  1581. initial fill = 0
  1582.  
  1583. width = 34, lines = 6, columns = 3
  1584.  
  1585. # other alignments
  1586. hgap = 0, vgap = 0, offset = 0
  1587.  
  1588. # Reformat each line
  1589. format of line  1 : "From: %s"
  1590. format of line  2 : "      %s"
  1591. format of line  3 : "      %s"
  1592. format of line  4 : "      %s"
  1593. format of line  5 : "      %s"
  1594. format of line  6 : "      %s"
  1595. SHAR_EOF
  1596. echo shar: extracting "'6080t.lbl'" '(377 characters)'
  1597. if test -f '6080t.lbl'
  1598. then
  1599.     echo shar: over-writing existing file "'6080t.lbl'"
  1600. fi
  1601. cat << \SHAR_EOF > '6080t.lbl'
  1602. # Same as Form 1083 with "To:"
  1603. # Last changed: 8/2/87 by Joe. Chen, USC-UCC
  1604.  
  1605. initial fill : 0
  1606.  
  1607. width : 34, lines : 6, columns : 3
  1608.  
  1609. # other alignments
  1610. hgap : 0, vgap : 0, offset : 0
  1611.  
  1612. # Reformat each line
  1613. format of line  1 : "To: %s"
  1614. format of line  2 : "    %s"
  1615. format of line  3 : "    %s"
  1616. format of line  4 : "    %s"
  1617. format of line  5 : "    %s"
  1618. format of line  6 : "    %s"
  1619. SHAR_EOF
  1620. echo shar: extracting "'6083.lbl'" '(209 characters)'
  1621. if test -f '6083.lbl'
  1622. then
  1623.     echo shar: over-writing existing file "'6083.lbl'"
  1624. fi
  1625. cat << \SHAR_EOF > '6083.lbl'
  1626. # Xerox 6083 (34 chars x 9 lines, 3 cols) for laser printing
  1627. # Last changed: 8/3/87 by Joe. Chen, USC-UCC
  1628.  
  1629. initial fill = 0
  1630.  
  1631. width = 34, lines = 9, columns = 3
  1632.  
  1633. # other alignments
  1634. hgap 0; vgap : 0, offset = 2
  1635. SHAR_EOF
  1636. echo shar: extracting "'6083f.lbl'" '(453 characters)'
  1637. if test -f '6083f.lbl'
  1638. then
  1639.     echo shar: over-writing existing file "'6083f.lbl'"
  1640. fi
  1641. cat << \SHAR_EOF > '6083f.lbl'
  1642. # Same as Form 6083 with "From:"
  1643. # Last changed: 8/2/87 by Joe. Chen, USC-UCC
  1644.  
  1645. initial fill = 0
  1646.  
  1647. width = 34, lines = 9, columns = 3
  1648.  
  1649. # other alignments
  1650. hgap = 0, vgap = 0, offset = 0
  1651.  
  1652. # Reformat each line
  1653. format of line  1 : "From: %s"
  1654. format of line  2 : "      %s"
  1655. format of line  3 : "      %s"
  1656. format of line  4 : "      %s"
  1657. format of line  5 : "      %s"
  1658. format of line  6 : "      %s"
  1659. format of line  7 : "      %s"
  1660. format of line  8 : "      %s"
  1661. SHAR_EOF
  1662. echo shar: extracting "'6083t.lbl'" '(435 characters)'
  1663. if test -f '6083t.lbl'
  1664. then
  1665.     echo shar: over-writing existing file "'6083t.lbl'"
  1666. fi
  1667. cat << \SHAR_EOF > '6083t.lbl'
  1668. # Same as Form 6083 with "To:"
  1669. # Last changed: 8/2/87 by Joe. Chen, USC-UCC
  1670.  
  1671. initial fill : 0
  1672.  
  1673. width : 34, lines : 9, columns : 3
  1674.  
  1675. # other alignments
  1676. hgap : 0, vgap : 0, offset : 0
  1677.  
  1678. # Reformat each line
  1679. format of line  1 : "To: %s"
  1680. format of line  2 : "    %s"
  1681. format of line  3 : "    %s"
  1682. format of line  4 : "    %s"
  1683. format of line  5 : "    %s"
  1684. format of line  6 : "    %s"
  1685. format of line  7 : "    %s"
  1686. format of line  8 : "    %s"
  1687. SHAR_EOF
  1688. #    End of shell archive
  1689. exit 0
  1690.